package main

import (
	"strings"
)

/**
 *
 * @param s string字符串
 * @return string字符串一维数组
 */
func restoreIpAddresses(s string) []string {
	res = []string{}
	segSlice = make([]string, SEG_COUNT)

	dfs(s, 0)
	return res
}

const SEG_COUNT = 4

var (
	res      []string
	segSlice []string
)

func dfs(s string, seg_index int) {
	if len(s) == 0 || seg_index == SEG_COUNT {
		if len(s) == 0 && seg_index == SEG_COUNT {
			res = append(res, strings.Join(segSlice, "."))
		}
		return
	}
	addr := 0
	for j := 0; j < len(s); j++ {
		addr = addr*10 + int(s[j]-'0')
		if addr > 0 && addr <= 255 {
			segSlice[seg_index] = s[:j+1]
			dfs(s[j+1:], seg_index+1)
		} else {
			if addr == 0 {
				segSlice[seg_index] = s[:j+1]
				dfs(s[j+1:], seg_index+1)
			}
			break
		}
	}
}
